package com.tiancheng.trade.merchant.channel.config;

import com.tiancheng.commom.pay.gaocheng.GcPayProperties;
import com.tiancheng.trade.commom.core.exception.error.BusinessErrorInfoEnum;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Optional;

/**
 * 高成支付渠道配置文件
 */
@Component
@Getter
@Setter
@ConfigurationProperties(prefix = "channel")
public class GcChannelProperties {

    private List<GcChannelPropertiesItem> gcNongHang;

    public GcChannelPropertiesItem getByOrgPayChannelId(Long orgPayChannelId){
        BusinessErrorInfoEnum.CHANNEL_PAY_FAIL.assertIsTrue(null!=orgPayChannelId && CollectionUtils.isNotEmpty(this.getGcNongHang()));
        final Optional<GcChannelPropertiesItem> first = this.getGcNongHang().stream().filter(u -> u.getOrgPayChannelId().equals(orgPayChannelId)).findFirst();
        BusinessErrorInfoEnum.CHANNEL_PAY_FAIL.assertIsTrue(first.isPresent());
        return first.get();
    }

    @Getter
    @Setter
    public static class GcChannelPropertiesItem{
        private Long orgPayChannelId;
        /**
         * 接口基础域名
         */
        private String host;
        /**
         * 主商户编号
         */
        private String mchNo;
        /**
         * 开发者 ID
         */
        private String accessId;
        /**
         * 签名密钥
         */
        private String accessSecret;
        /**
         * 通知地址
         */
        private String notifyUrl;
    }
}
